package com.example.echoewish.repository.network;

import com.example.echoewish.pojo.User;
import com.example.echoewish.repository.network.service.UserService;
import com.example.echoewish.util.ServiceCreator;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Callback;


public class UserServiceNetwork {

    public static void registerNewUsers(String account, String password, Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        userService.registerNewUsers(account,password).enqueue(callback);
    }

    public static void loginOn(String account, String password, Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        userService.loginOn(account,password).enqueue(callback);
    }

    public static void queryUserByUserId(int userId,Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        userService.queryUserByUserId(userId).enqueue(callback);
    }

    public static void updateUserHeadImage(int userId, File image, Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        RequestBody body=null;
        if(image!=null)
        {

            MultipartBody.Builder builder = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("image","post.postImage",RequestBody.create(image, MediaType.parse("image/*")))
                    .addFormDataPart("userId", String.valueOf(userId));
            body=builder.build();
            userService.updateUserHeadImage(body).enqueue(callback);
        }
    }

    public static void updateUserInfo(User user,Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        userService.updateUserInfo(user.userId,user.name,user.sex,user.grade,user.campus).enqueue(callback);
    }

    public static void getFriendMessage(int userId,int friId,Callback callback)
    {
        UserService userService=new ServiceCreator().create(UserService.class);
        userService.getFriendMessage(userId,friId).enqueue(callback);
    }
}
